package com.junbao.message.infrastructure.core.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.junbao.commom.context.ClassPathXmlApplicationContext;
import com.junbao.message.application.service.MessageService;
import com.junbao.message.domain.model.NotifyMessage;
import com.junbao.message.infrastructure.core.DataConsumer;
import com.junbao.message.infrastructure.core.RequestDto;

/**
 * 死亡消费者
 * @author yilin
 *
 */
public class MessageDeadHandler extends DataConsumer<RequestDto<NotifyMessage>>{
	
	private static final Logger LOGGER = LoggerFactory.getLogger(MessageDeadHandler.class);
	
	private MessageService messageService = (MessageService) ClassPathXmlApplicationContext.getInstance().getBean("messageService");
	
	@Override
	public void onEvent(RequestDto<NotifyMessage> event) throws Exception {
		NotifyMessage notifyMessage = event.getBusinessObject();
		try {
			LOGGER.info(Thread.currentThread().getName()+" 序列号： "+notifyMessage.getMessageSquece()+" 执行死亡状态变更.");
			messageService.updateMessageToDead(notifyMessage);
		} catch (Exception e) {
			LOGGER.info("确认消息发送失败！消息详情=>"+notifyMessage.toString());
			LOGGER.error("消息序列号： "+notifyMessage.getMessageSquece(), e);
		}
	}

}
